package com.bawei.company

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.bean.AddCompanyEntity
import com.bawei.base.bean.ProcessingStep
import com.bawei.base.mvvm.BaseActivity
import com.bawei.company.databinding.ActivityAddCompanyBinding
import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.blankj.utilcode.util.ToastUtils
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat

@AndroidEntryPoint
@Route(path = "/company/AddCompanyActivity")
class AddCompanyActivity : BaseActivity<ActivityAddCompanyBinding, CompanyViewModel>() {
    override fun initView() {
        binding.etCompanyTime.setOnClickListener {
            TimePickerBuilder(this) { data, _ ->
                run {
                    binding.etCompanyTime.text = SimpleDateFormat("yyyy-MM-dd").format(data)
                }
            }.build().show()
        }
        binding.btnSubmit.setOnClickListener {
            val addCompanyEntity = AddCompanyEntity()
            var list= mutableListOf<ProcessingStep>()
            addCompanyEntity.apply {
                applicationArea = binding.etCompanyArea.text.toString().toInt()
                contactMethod = binding.etCompanyPhone.text.toString()
                contactName = binding.etCompanyPerson.text.toString()
                enterpriseName = binding.etCompanyName.text.toString()
                entryTime = binding.etCompanyTime.text.toString()
                processingSteps = list
                entryPersonnel= binding.etCompanyPersonNumber.text.toString().toInt()
                applicationNumber= "QX"+binding.etCompanyPhone.text.toString()+ binding.etCompanyArea.text.toString()

            }
            viewModel.addCompany(addCompanyEntity)
        }
        binding.companyVisit.setOnClickListener {
            ARouter.getInstance().build("/company/CompanyApplyActivity").navigation()
        }
    }

    override fun initData() {
        viewModel.addcompanySuccess.observe(this){
            ToastUtils.showLong("提交成功")
        }
    }
}